package com.iwhalecloud.bss.kite.cucc.web.controller.order;

import com.github.pagehelper.PageInfo;
import com.iwhalecloud.bss.kite.client.api.traceLog.IKiteServiceLogService;
import com.iwhalecloud.bss.kite.cart.common.constant.KiteCartErrorConsts;
import com.iwhalecloud.bss.kite.client.dto.DataResult;
import com.iwhalecloud.bss.kite.client.dto.log.KiteCartServiceLog;
import com.iwhalecloud.bss.kite.manager.transaction.KiteTransactional;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Jonathan
 */
@RestController
@RequestMapping("/log")
@Api(tags = {
    "/log - 日志接口"
})
public class KiteServiceLogController {

    @Autowired
    private IKiteServiceLogService serviceLogService;

    @ApiOperation(value = "根据主键查询日志", notes = "根据主键查询日志")
    @GetMapping("/getLog")
    public DataResult<KiteCartServiceLog> getLogById(@RequestParam Long id) {
        return KiteCartErrorConsts.SUCCESS.getResult(serviceLogService.getLogByLogId(id));
    }

    @ApiOperation(value = "根据TraceId查询日志", notes = "根据TraceId查询日志")
    @GetMapping("/getLogByTraceId")
    public DataResult<List<KiteCartServiceLog>> getLogByTraceId(@RequestParam String traceId) {
        return KiteCartErrorConsts.SUCCESS.getResult(serviceLogService.getLogByTraceId(traceId));
    }

    @ApiOperation(value = "分页查询日志", notes = "分页查询日志")
    @GetMapping("/getLogByPage")
    public DataResult<PageInfo<KiteCartServiceLog>> getLogByPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        return KiteCartErrorConsts.SUCCESS.getResult(serviceLogService.getLogByPage(pageNum, pageSize));
    }

    @KiteTransactional
    @ApiOperation(value = "添加日志", notes = "添加日志")
    @PostMapping("/addLog")
    public DataResult addLog(@RequestBody KiteCartServiceLog serviceLog) {
        serviceLogService.addLog(serviceLog);
        return KiteCartErrorConsts.SUCCESS.getResultWithoutObject();
    }
}
